using Godot;
using System;

namespace EnemyStateNode
{
public partial class Jump : Node,StateNode
{
	public Enemy enemy;

	public override void _Ready()
	{
		enemy = GetNode<Enemy>("/root/Main/Enemy");
	}

    public void OnEnter()
    {
        enemy.GetNode<AnimatedSprite2D>("AnimaEnemy").Animation="jump";
        enemy.Velocity = new(0,enemy.JumpVelocity);
    }

    public void OnUpdate(float delta)
    {
		if(enemy.Health<=0)
			enemy.SwitchTo("Dead");
        else if(enemy.Velocity.Y>=0)
        {
            {
                int randNum=(int)MyUtil.RangeRandom(1,100);
                if(enemy.Health>5)
                {
                    if(randNum<=50)
                        enemy.SwitchTo("Aim");
                    else if(randNum<=80)
                        enemy.SwitchTo("Fall");
                    else
                        enemy.SwitchTo("ThrowSilk");
                }
                else
                {
                    if(randNum<=50)
                        enemy.SwitchTo("Aim");
                    else if(randNum<=80)
                        enemy.SwitchTo("Fall");
                    else
                        enemy.SwitchTo("ThrowSilk");
                }
            }   
        }
        
    }

    public void OnExit(){}
}

}
